package com.mintomato.learning.sort;

/**
 * @author weichaoo
 * @date 2012-8-21
 */
public class InsertSort {

	/**
	 * @param array
	 * @return
	 */
	public int[] sort(int[] array){
		System.out.println("原始数组: "+ Tools.printArray(array));
		for(int i = 1; i < array.length; i++){
			int key = array[i];
			int j = i-1;
			while(j >= 0 && array[j] > key){
				array[j+1] = array[j];
				j = j-1;
			}
			array[j+1] = key;
			System.out.println("第" + i + "次: " + Tools.printArray(array));
		}
		return array;
	}
	
	
	
	public static void main(String[] args) {
		InsertSort insertSort = new InsertSort();
		int[] array = {8,2,4,9,3,6};
		insertSort.sort(array);
	}
}
